package com.bird.component.lang.common.jackson

import com.fasterxml.jackson.databind.BeanDescription
import com.fasterxml.jackson.databind.DeserializationConfig
import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.databind.module.SimpleDeserializers
import com.fasterxml.jackson.databind.util.EnumResolver

class CustomizeDeserializers : SimpleDeserializers() {
    @Throws(JsonMappingException::class)
    override fun findEnumDeserializer(type: Class<*>, config: DeserializationConfig, beanDesc: BeanDescription): JsonDeserializer<*> {
        return if (Enum::class.java.isAssignableFrom(type)) {
            com.bird.component.lang.common.jackson.CustomizeEnumDeserializer(EnumResolver.constructFor(config, type))
        } else super.findEnumDeserializer(type, config, beanDesc)
    }
}